const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

function gotoLogin(){
  wx.showModal({
    title: '登录提醒',
    content: '用户未登录，请前往登录享受更多权益！',
    confirmText:'前往'
  }).then(res=>{
    if(res.confirm){
      wx.switchTab({
        url: '/pages/mine/mine',
      });
    }
  })
}

function loginTip(){
  wx.showToast({
    title: '登录享受更多权益',
    icon:'none',
    duration:1000
  });
}
//判断日期是否需要加0
function addZero(num){
  return num < 10 ? '0' + num:num 
}

module.exports = {
  formatTime,
  gotoLogin,
  loginTip,
  addZero
}
